/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.gui.model;

import java.text.NumberFormat;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import program.beans.BillAmount;

/**
 * TableModel for NewBillDlg with columns 'Bruttobetrag', 'Prozentsatz' and
 * 'Nettobetrag'
 *
 * Responsible: Patrick
 */
public class AmountTableModel extends AbstractTableModel {

    private ArrayList<BillAmount> amounts;
    private String headLines[] = {"Bruttobetrag", "Prozentsatz", "Nettobetrag"};

    public AmountTableModel(ArrayList<BillAmount> amounts) {
        this.amounts = amounts;
    }

    @Override
    public int getRowCount() {
        return amounts.size();
    }

    @Override
    public int getColumnCount() {
        return headLines.length;
    }

    @Override
    public String getColumnName(int column) {
        return headLines[column];
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        BillAmount ba = amounts.get(rowIndex);

        switch (columnIndex) {
            case 0:
                return NumberFormat.getCurrencyInstance().format(ba.getBrutto().doubleValue());
            case 1:
                return ba.getPercentage() + "%";
            case 2:
                return NumberFormat.getCurrencyInstance().format(ba.getNetto().doubleValue());
            default:
                return null;
        }
    }
}